#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>

#define PAT "/home/zhang/"

int main(int argc, char * argv[])
{
	//DIR类型指针
	DIR * dp;
	//定义结构体类型指针
	struct dirent * cur;
	//打开目录
	dp = opendir(PAT);
	if(dp == NULL)
	{
		perror("opendir");
		exit(1);
	}
	//读取目录下的内容
	while(((cur = readdir(dp))) != NULL)
		puts(cur->d_name);

	//关闭目录
	closedir(dp);

	exit(0);
}

